﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.JoinParty;
using ZHDJ.JoinParty.BLL;

namespace JoinParty.admin.ToDoFlow
{
    public partial class ShowFlowStep : PageBase
    {
        #region 属性
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.LoadData();
            }
        }

        #region 数据访问

        /// <summary>
        /// LoadData
        /// </summary>
        protected void LoadData()
        {
            ZHDJ.Core.Log.Log4netHelper.WriteLog(this.AppllicationID.ToString());
            this.rpFlow.DataSource = PartyJoinLinkExample.GetGridData(this.AppllicationID);
            this.rpFlow.DataBind();
            link8.NavigateUrl = "../../Template/TJoinStep08.aspx?AppllicationID=" + this.AppllicationID;
            link9.NavigateUrl = "../../Template/TJoinStep09.aspx?AppllicationID=" + this.AppllicationID;
            link15.NavigateUrl = "../../Template/TJoinStep15All.aspx?AppllicationID=" + this.AppllicationID;
            link19.NavigateUrl = "../../Template/TJoinStep19.aspx?AppllicationID=" + this.AppllicationID;
            link25.NavigateUrl = "../../Template/TJoinStep25.aspx?AppllicationID=" + this.AppllicationID;
            link31.NavigateUrl = "../../Template/TJoinStep31.aspx?AppllicationID=" + this.AppllicationID;
            link35.NavigateUrl = "../../Template/TJoinStep35.aspx?AppllicationID=" + this.AppllicationID;
        }

        /// <summary>
        /// 通过流程状态值获取状态名称
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public static string GetStatusName(string status)
        {
            string retStr = string.Empty;
            string retStrEx = string.Empty;

            int intStatus = 0;
            try
            {
                if (!string.IsNullOrEmpty(status))
                {
                    intStatus = Convert.ToInt16(status);
                    retStr = Enum.GetName(typeof(Enum_FlowStanceStatus), intStatus);
                    if (retStr == "未处理")
                    {
                        retStrEx = "<a style='color:red'>" + retStr + "</a>";
                    }
                    else retStrEx = retStr;
                }
            }
            catch (Exception ex)
            {
                retStr = "";
            }
            return retStrEx;
        }

        /// <summary>
        /// 获取详细信息地址
        /// </summary>
        /// <param name="StandID">流程ID</param>
        /// <returns></returns>
        public static string GetDetailedInfor(string StandID)
        {
            string url = "#";
            if (!string.IsNullOrEmpty(StandID))
            {
                url = "" + StandID;
            }
            return url;
        }
        #endregion

        protected void rpFlow_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                LinkButton gridFLowOper = e.Item.FindControl("gridFLowOper") as LinkButton;
                HiddenField hf_StepID = e.Item.FindControl("hf_StepID") as HiddenField;
                HiddenField hf_StandID = e.Item.FindControl("hf_StandID") as HiddenField;
                HiddenField hf_BranchID = e.Item.FindControl("hf_BranchID") as HiddenField;
                HiddenField hf_AppllicationID = e.Item.FindControl("hf_AppllicationID") as HiddenField;

                if (gridFLowOper != null)
                {
                    //gridFLowOper.DialogParentContainerID = "editDialog";
                    //gridFLowOper.DialogID = "editDialog";
                    string stepID = hf_StepID != null ? hf_StepID.Value : "";
                    string standID = hf_StandID != null ? hf_StandID.Value : "";
                    string BranchID = hf_BranchID != null ? hf_BranchID.Value : "";
                    string AppllicationID = hf_AppllicationID != null ? hf_AppllicationID.Value : "";
                    string queryParam = string.Format("?StandID={0}&ApplyBranchID={1}&CurrentStepID={2}&ApplyID={3}&ReadOnly=1", standID, BranchID, stepID, AppllicationID);
                    switch (stepID)
                    {
                        case ProcesUtil.JoinStep1:
                            gridFLowOper.OnClientClick = DialogMeetingStep.GetShowReference("../ApplyJoin/ApplyJoinPartyEdit.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep2://登记备案

                        case ProcesUtil.JoinStep10://入党积极份子培训
                        case ProcesUtil.JoinStep13://确定发展对象
                        case ProcesUtil.JoinStep16://计划生育及社会治安等审查
                        case ProcesUtil.JoinStep17://发展对象集中培训
                        case ProcesUtil.JoinStep18://确定入党介绍人
                        //case ProcesUtil.JoinStep19://填写入党志愿书
                        case ProcesUtil.JoinStep20://支部委员会审查
                        case ProcesUtil.JoinStep21://基层党委预审
                        case ProcesUtil.JoinStep25://组织员谈话

                        case ProcesUtil.JoinStep32://提出书面转正申请
                        case ProcesUtil.JoinStep33://党小组意见
                        //case ProcesUtil.JoinStep34://党支部意见

                        case ProcesUtil.JoinStep40://入党材料归档
                        case ProcesUtil.JoinStep6://入党积极份子报上级党委审查备案
                        case ProcesUtil.JoinStep14://报上级党委审查备案
                            gridFLowOper.OnClientClick = Dialog.GetShowReference("../FlowStep/Registration.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep5://确认入党积极分子
                            gridFLowOper.OnClientClick = Dialog.GetShowReference("../FlowStep/RegistrationStepFive.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep15:
                            gridFLowOper.OnClientClick = Dialog.GetShowReference("../FlowStep/Examination.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep4: //入党积极份子公示
                        case ProcesUtil.JoinStep12: //发展对象公示
                        case ProcesUtil.JoinStep24: //预备党员公示
                        case ProcesUtil.JoinStep36:
                            gridFLowOper.OnClientClick = Dialog.GetShowReference("../FlowStep/Registration.aspx" + queryParam, "查看");
                            break;

                        case ProcesUtil.JoinStep27://下发通知
                        case ProcesUtil.JoinStep28://公布预备党员并编入党组织
                        //case ProcesUtil.JoinStep36://预备党员转正公示
                        case ProcesUtil.JoinStep39://谈话和公布预备党员转正
                            gridFLowOper.OnClientClick = Dialog.GetShowReference("../FlowStep/Published.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep7://指定培养联系人
                            gridFLowOper.OnClientClick = Dialog.GetShowReference("../FlowStep/AppointCultivateContacts.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep8://填写入党积极分子考察表
                            gridFLowOper.OnClientClick = WJoinStep7.GetShowReference("../FlowStep/SubActivistInvestigate.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep30://填写预备党员考察表
                            gridFLowOper.OnClientClick = DialogKaoCaBiao.GetShowReference("../FlowStep/ProPartymemberInspection.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep23:/// 上报审批材料
                        case ProcesUtil.JoinStep37:/// 上报审批材料（共12份材料）
                        case ProcesUtil.JoinStep38://党委审核（3个月内）及批复
                            gridFLowOper.OnClientClick = WShangBao2.GetShowReference("../FlowStep/Report.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep9://入党积极份子培养和考察
                        case ProcesUtil.JoinStep31://预备党员教育考察                      
                            gridFLowOper.OnClientClick = WJoinStep8.GetShowReference("../FlowStep/JoinPartyInspection.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep3://推荐入党积极份子
                        case ProcesUtil.JoinStep11://推荐党员发展对象
                        case ProcesUtil.JoinStep22://支部大会讨论接收预备党员
                        case ProcesUtil.JoinStep26://审批预备党员
                        case ProcesUtil.JoinStep35://支部大会讨论预备党员转正
                            gridFLowOper.OnClientClick = DialogMeetingStep.GetShowReference("../FlowStep/MeetingEx.aspx" + queryParam, "查看");
                            break;
                        //case ProcesUtil.JoinStep14://报上级党委审查备案
                        //    break;
                        case ProcesUtil.JoinStep29://组织宣誓
                            gridFLowOper.OnClientClick = Dialog.GetShowReference("../FlowStep/OrganizationOath.aspx" + queryParam, "查看");
                            break;
                        case ProcesUtil.JoinStep19:
                            gridFLowOper.OnClientClick = wStep19.GetShowReference("../FlowStep/JoinPartyAppllication.aspx" + queryParam, "查看");
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
}